// Created by MyEclipse Struts
// XSL source (default):
// platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.4/xslt/JavaClass.xsl

package com.novix.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.novix.portal.framework.exceptions.BusinessException;
import com.novix.portal.framework.util.IConstants;
import com.novix.struts.form.AdminForm;
import com.novix.utility.web.CacheCleaner;
import com.opensymphony.oscache.base.CacheEntry;
import com.opensymphony.oscache.base.NeedsRefreshException;
import com.opensymphony.oscache.general.GeneralCacheAdministrator;

/**
 * MyEclipse Struts Creation date: 06-26-2005 XDoclet definition:
 * 
 * @struts:action path="/admin" name="adminForm" input="/form/admin.jsp"
 *                scope="request" validate="true"
 */
public class AdminAction extends Action {

    // --------------------------------------------------------- Instance
    // Variables

    // --------------------------------------------------------- Methods

    /**
     * Method execute
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        AdminForm adminForm = (AdminForm) form;
        if (isCancelled(request))
            return mapping.findForward(IConstants.HOME);
        else {
            GeneralCacheAdministrator admin = (GeneralCacheAdministrator) request.getSession().getServletContext().getAttribute(IConstants.OS_CACHE_ADMIN);
            try {
                CacheCleaner cleaner = (CacheCleaner) admin.getFromCache(IConstants.CACHE_CLEANER, CacheEntry.INDEFINITE_EXPIRY);
                cleaner.run();
                return mapping.findForward(IConstants.SUCCESS);
            } catch (NeedsRefreshException e) {
                throw new BusinessException("no cache cleaner found in memory", e);
            }
        }
    }

}